﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Diagnostics;
using System.Threading;

namespace VisualCrypto
{
    public enum MODES{ MonoAlgo, New};

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            LayoutMdi(MdiLayout.TileHorizontal);

        }
        Bitmap[] bitmaps = new Bitmap[2];
        
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            OpenFileDialog opd = new OpenFileDialog();
            opd.Filter = "*jpegs|*.jpg";
            opd.Multiselect = false;
            if (opd.ShowDialog() == DialogResult.OK)
            {
                ChildForm cf = new ChildForm();
                cf.MdiParent = this;
                cf.picbox.Image = Bitmap.FromFile(opd.FileName);
                
                cf.Show();
                LayoutMdi(MdiLayout.TileHorizontal);
            }



        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChildForm active = (ChildForm)this.ActiveMdiChild;
            if (active != null)
            {
                active.picbox.Image.Save(@"C:\Users\Jin\Desktop\STUDIA\\test.bmp", ImageFormat.Bmp);
            }


        }


        #region  MonoAlgorithm Encryption Decription


        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            bitmaps = (Bitmap[])e.Result;
            ChildForm cf = new ChildForm();
            cf.MdiParent = this;

            ChildForm cf2 = new ChildForm();
            cf2.MdiParent = this;
            cf.picbox.Image = (Image)bitmaps[0];
            // NOISE #2
            cf2.picbox.Image = (Image)bitmaps[1];




            cf.Show();
            cf2.Show();

           
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            Bitmap[] temp = new Bitmap[2];
            Bitmap image1 = (Bitmap)e.Argument;
            temp = Algo.MonoAlgorithmEncryption(image1);
            e.Result = temp;
        }


        /* Encryption */
        private void encryptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BackgroundWorker backgroundWorker1 = new BackgroundWorker();
            backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
            backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
            
            ChildForm cf1 = (ChildForm)this.ActiveMdiChild;
            Bitmap image1 = (Bitmap)cf1.picbox.Image;
           
            backgroundWorker1.RunWorkerAsync(image1);

           
            
          
           
        

        }

        /* Decyrption */
        private void decryptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            int amount = this.MdiChildren.Length;
            ChildForm cf1 = (ChildForm)this.MdiChildren[amount-1];
            ChildForm cf2 = (ChildForm)this.MdiChildren[amount-2];
           
           cf1.Close();
           cf2.Close();
           LayoutMdi(MdiLayout.TileHorizontal);
            Bitmap image1 = (Bitmap)cf1.picbox.Image;
            Bitmap image2 = (Bitmap)cf2.picbox.Image;
            ChildForm cf = new ChildForm(image1, image2, MODES.MonoAlgo);
            cf.MdiParent = this;

            cf.Show();
            LayoutMdi(MdiLayout.TileHorizontal);

            }     
   
          
       }

        #endregion












        }

      

        









   

